package Chinese.Education.Identify.service;

import Chinese.Education.Identify.mapper.StudentMapper;
import Chinese.Education.Identify.pojo.Student;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StudentService {

    @Resource
    private StudentMapper studentMapper;
    //查看操作
    public  Map<String,Object> selectStudent(int page, int limit,String school,String grade){
        int offset = (page - 1) * limit;          // 计算偏移
        List<Student> list = studentMapper.selectByPage(offset, limit,school,grade);
        int total = studentMapper.selectStudentcount();
        Map<String, Object> result = new HashMap<>();
        result.put("code", 0);
        result.put("msg", "");
        result.put("count", total);
        result.put("data", list);
        return result;

    };
    //新增操作
    public Map<String, Object> insert(Student student){
        Map<String,Object> map = new HashMap<>();
        studentMapper.insert(student);
        map.put("code",200);
        map.put("msg","新增成功");
        map.put("data",student);
        return map;
    }

    //更新操作
    public Map<String, Object> update(Student student){
        Map<String,Object> map = new HashMap<>();
        studentMapper.update(student);
        map.put("code",200);
        map.put("msg","新增成功");
        map.put("data",student);
        return map;
    }

    //删除操作
    public Map<String, Object> delete(Student student){
        Map<String,Object> map = new HashMap<>();
        studentMapper.delete(student);
        map.put("code",200);
        map.put("msg","删除成功");
        map.put("data",student);
        return map;
    }



}
